package com.hengxinguotong.hxgtwygsp.ui.supervise.satisfaction;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hengxinguotong.hxgtwygsp.R;
import com.hengxinguotong.hxgtwygsp.model.Year;
import com.hengxinguotong.hxgtwygsp.ui.base.BaseTabFragment;
import com.hengxinguotong.hxgtwygsp.widget.DropListPW;
import com.hengxinguotong.hxgtwygsp.widget.YearPW;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * TODO 满意度测评
 *
 * @author hjz
 * @version V1.0.0
 * @since 2019/4/10 13:19
 */
public class SatisfactionFragment extends BaseTabFragment implements SatisfactionContract.IView,
        DropListPW.OnClickCallback<Year> {
    @Inject
    SatisfactionContract.IPresenter mPresenter;
    @BindView(R.id.satisfaction_year)
    TextView mSatisfactionYear;
    @BindView(R.id.satisfaction_year_container)
    RelativeLayout mSatisfactionYearContainer;
    @BindView(R.id.iv_1)
    ImageView mIv1;
    @BindView(R.id.iv_2)
    ImageView mIv2;
    @BindView(R.id.iv_3)
    ImageView mIv3;
    @BindView(R.id.satisfaction_range)
    LinearLayout mSatisfactionRange;
    @BindView(R.id.satisfaction_score_container)
    LinearLayout mSatisfactionScoreContainer;


    private List<Year> yearList;

    public SatisfactionFragment() {
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mPresenter.bindView(this);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mPresenter.dropView();
    }

    @Override
    public int getLayoutResId() {
        return R.layout.fragment_satisfaction;
    }

    @Override
    public void init() {
        yearList = new ArrayList<>();
        Calendar calendar = Calendar.getInstance();
        mSatisfactionYear.setText(getString(R.string.patrol_year, calendar.get(Calendar.YEAR)));
        Year year;
        for (int i = 0; i < 3; i++) {
            year = new Year();
            year.setName(getString(R.string.patrol_year, calendar.get(Calendar.YEAR)));
            yearList.add(year);
            calendar.add(Calendar.YEAR, -1);
        }
    }

    @OnClick(R.id.satisfaction_year_container)
    public void onViewClicked(View view) {
        YearPW yearPW = new YearPW(getContext(), view.getWidth());
        yearPW.setOnClickCallback(this);
        yearPW.initData(yearList, 0);
        yearPW.showAsDropDown(view);
    }

    @Override
    public void onClickPW(Year year) {
        mSatisfactionYear.setText(year.getName());
    }

}
